#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "shunxudui.h"

void test_InSequeue(){
    printf("__________插入测试_________\n");
    {//p=null
        
        InSequeue(NULL, 0);

    }
    {//p !=null 测试超出容量的插入
        sequeue_t *queue = CreateEmptySequeue();
        InSequeue(queue, 0);
        InSequeue(queue, 1);
        InSequeue(queue, 2);
        InSequeue(queue, 3);
        InSequeue(queue, 4);
        InSequeue(queue, 5);
        InSequeue(queue, 6);
        if(queue->data[3] == 3){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }

    {//p !=null 测试下标p->rear
        int true=-1;
        sequeue_t *queue = CreateEmptySequeue();
        InSequeue(queue, 0);
        if(queue->rear == 1){
            true=1;
        }else{
            true=0;
        }
        InSequeue(queue, 1);
        InSequeue(queue, 2);
        InSequeue(queue, 3);
        InSequeue(queue, 4);
        if(queue->rear == 4 && queue->front == 0){
            true=1;
        }else{
            true=0;
        }
        if(true == 1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }

    {//p !=null 测试下标p->rear
        int true=-1;
        sequeue_t *queue = CreateEmptySequeue();
        InSequeue(queue, 0);
        if(queue->rear == 1){
            true=1;
        }else{
            true=0;
        }
        InSequeue(queue, 1);
        InSequeue(queue, 2);
        InSequeue(queue, 3);
        //模拟出列
        queue->front++;

        InSequeue(queue, 4);
        if(queue->rear == 0){
            true=1;
        }else{
            true=0;
        }
        if(true == 1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }

    {//正常插入
        sequeue_t *queue = CreateEmptySequeue();
        int true=-1;
        InSequeue(queue, 0);
        InSequeue(queue, 1);
        InSequeue(queue, 2);
        InSequeue(queue, 3);
        for(int i =0;i<4;i++){
            if(queue->data[i] == i){
                true=1;
            }else{
                true=-1;
                break;
            }
        }
        if(true == 1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }
    

    printf("__________插入测试_________\n");
}

void test_OutSequeue(){
    printf("__________出列测试_________\n");
    {//p == null
        if(OutSequeue(NULL) == -1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        
    }

    {//队列为空
        sequeue_t *queue = CreateEmptySequeue();
        if(OutSequeue(queue) == -1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }
    
    {//队列非空
        sequeue_t *queue = CreateEmptySequeue();
        //模拟入队
        queue->rear++;
        if(OutSequeue(queue) == 1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }
    
    {//出队位置是否正确//p->front移动是否正确
        sequeue_t *queue = CreateEmptySequeue();
        //模拟入队
        queue->rear++;
        OutSequeue(queue);
        if(queue->front == 1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }
    
    
    printf("__________出列测试_________\n");
}

void test_IsFullSequeue(){
    printf("__________判断满测试_________\n");
    {//p=null 
        if(IsFullSequeue(NULL) == -1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
    }

    //p != null
    {//不满
        sequeue_t *queue = CreateEmptySequeue();
        //模拟入队
        queue->rear++;

        if(IsFullSequeue(queue) == 0){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }

    {//满
        sequeue_t *queue = CreateEmptySequeue();
        //模拟入队
        queue->rear+=4;

        if(IsFullSequeue(queue) == 1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }

    {//空
        sequeue_t *queue = CreateEmptySequeue();

        if(IsFullSequeue(queue) == 0){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }
    printf("__________判断满测试_________\n");
}

void test_IsEmptySequeue(){
    printf("__________判断空测试_________\n");
    {//p == null
        if(IsEmptySequeue(NULL) == -1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
    }

    //p != null
    {//空
        sequeue_t *queue = CreateEmptySequeue();

        if(IsEmptySequeue(queue) == 1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }

    {//非空
        sequeue_t *queue = CreateEmptySequeue();
        //模拟入队
        queue->rear++;
        if(IsEmptySequeue(queue) == 0){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;

    }
    printf("__________判断空测试_________\n");
}

void test_LengthSequeue(){
    printf("__________长度测试_________\n");
    {//p == null
        if(LengthSequeue(NULL) == -1){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
    }

    //p != null
    {//空
        sequeue_t *queue = CreateEmptySequeue();

        if(LengthSequeue(queue) == 0){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;
    }

    //非空
    {//p->rear > p->front
        sequeue_t *queue = CreateEmptySequeue();
        //模拟入队
        queue->rear+=2;
        if(LengthSequeue(queue) == 2){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;

    }

    {//p->rear < p->front
        sequeue_t *queue = CreateEmptySequeue();
        //模拟入队
        queue->front+=2;
        if(LengthSequeue(queue) == 2){
            printf("成功!\n");
        }else{
            printf("失败!\n");
        }
        free(queue);
        queue=NULL;

    }
    printf("__________长度测试_________\n");
}



int main(void) {

    test_InSequeue();
    test_OutSequeue();
    test_IsFullSequeue();
    test_IsEmptySequeue();
    test_LengthSequeue();

    return 0;
}

